class Solution {
public:

    string multiply(string num1, string num2) {
        if (num1 == "0" || num2 == "0")
            return "0";

        int m = num1.size(), n = num2.size();
        vector<int> tmp(m + n - 1);
        int end2 = n - 1;
        while (end2 >= 0)
        {
            int end1 = m - 1;
            while (end1 >= 0)
            {
                tmp[end1 + end2] += (num2[end2] - '0') * (num1[end1] - '0');
                end1--;
            }
            end2--;
        }
        string ret;
        int i = m + n - 2, t = 0;
        while (i >= 0 || t)
        {
            if (i >= 0)
                t += tmp[i--];
            ret += t % 10 + '0';
            t /= 10;
        }

        reverse(ret.begin(), ret.end());
        return ret;
    }



};